#!/usr/bin/ruby
# -*- coding: UTF-8 -*-

=begin 
@author = sirius
@time = 2017.11.8
=end

# 全局变量
$global_variable = 10
class Class1
  def print_global
      puts "全局变量在 Class1 中输出为 #$global_variable"
  end
end
class Class2
  def print_global
      puts "全局变量在 Class2 中输出为 #$global_variable"
  end
end
 
class1obj = Class1.new
class1obj.print_global
class2obj = Class2.new
class2obj.print_global

# 实例变量
class Customer
   @@no_of_customers=0 # 类变量
   def initialize(id, name, addr)
      @cust_id=id # 实例变量
      @cust_name=name # 实例变量
      @cust_addr=addr # 实例变量
   end
   def display_details()
      puts "Customer id #@cust_id"
      puts "Customer name #@cust_name"
      puts "Customer address #@cust_addr"
    end
    def total_no_of_customers()
       @@no_of_customers += 1 # 类变量
       puts "Total number of customers: #@@no_of_customers"
    end
end
 
# 创建对象
cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2=Customer.new("2", "Poul", "New Empire road, Khandala")
 
# 调用方法
cust1.display_details()
cust2.display_details()

# 类变量
cust1.total_no_of_customers()
cust2.total_no_of_customers()

# 常量
class Example
   VAR1 = 100
   VAR2 = 200
   def show
       puts "第一个常量的值为 #{VAR1}"
       puts "第二个常量的值为 #{VAR2}"
   end
end
 
# 创建对象
object=Example.new()
object.show